#include "config.h"

#ifdef ENABLE_POSTGRESQL

#ifdef WINDOWS
    #pragma comment (lib,"libpq.lib")
#endif

#include <map>
#include <string>
#include <libpq-fe.h>
#include "AbstractDatabase.h"

typedef std::map<std::string, PGconn*> MyPGconnMap;

class PGSQLDatabase : public AbstractDatabase{
public:

    /** Connection **/
	PGSQLDatabase(PString host, PString port, PString database, PString user, PString password);
	~PGSQLDatabase();
	bool isConnected(std::string database);

    /** Query **/
    PQuery query(String sqlQuery);
	PQuery query(PString database, String sqlQuery);

	PQuery select(PString database, PString schema, PString table, int option = OPTION_ALL);
	PQuery getTableInfoQuery(PString database, PString schema, PString table);
	PQuery getFieldListQuery(PString database, PString schema, PString table);

	/** List **/
	PQuery listDatabases();
	PQuery listSchemata(PString database);
    PQuery listTables(PString database, PString schema);

    void dropTable(PString database, PString schema, PString table);
    /** Exists check**/
    bool exists(PString database, PString schema, PString table);

    /** Other **/
	void rename(String oldname, String newname);

	friend class PGSQLQuery;
protected:
    MyPGconnMap connections;
};
#endif
